package com.example.mvvmkotlin.basetest

import android.app.Application
import android.util.Log
import androidx.databinding.ObservableField
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.example.mvvmkotlin.mvvm.UserModel
import com.fangmu.basemodule.BaseViewModel

/**
 * @ProjectName : MvvmKotlin
 * @Author : FangMu
 * @Time : 2023/11/23 14:32
 * @Description : ViewModel层
 */
open class LoginViewModel(application: Application) : BaseViewModel(application){

    val name = ObservableField<String>()
    val pwd = ObservableField<String>()
    private val _count = MutableLiveData<Int>()
    val count : LiveData<Int>
        get() = _count
    fun login() {
        val enterName = name.get()
        val enterPwd = pwd.get()
        _count.value = 20
//        _count.postValue(30)  在子线程中使用该方法
        if (enterPwd.isNullOrEmpty() || enterName.isNullOrEmpty()) {

        } else {
            val user = UserModel(enterName, enterPwd)
            Log.d("TAG", "login: 登录成功！！！")
        }
    }
}